# -*- coding: utf-8 -*-
# This code written by ChanGOGOGO
"""
登录&选择业务页面元素
"""
import sys
import os

current_script_dir = os.path.dirname(os.path.abspath(__file__))
parent_dir = os.path.dirname(current_script_dir)
if parent_dir not in sys.path:
    sys.path.append(parent_dir)
from pages.base_page import BasePage


class LoginPage(BasePage):
    def aiforce_id(self):
        """用户名输入框"""
        element = self.page.get_by_placeholder("AIForce ID")
        return element

    def password(self):
        """密码输入框"""
        element = self.page.get_by_placeholder("密码")
        return element


if __name__ == "__main__":
    from playwright.sync_api import sync_playwright

    url = "http://aiforce-pet.aibpo.ibot.ai/#/user/login"
    with sync_playwright() as playwright:
        browser = playwright.chromium.launch(
            headless=False, channel="chrome", args=["--start-maximized"]
        )
        context = browser.new_context(no_viewport=True)
        page = context.new_page()
        page.goto(url)
        login_page = LoginPage(page)
        login_page.aiforce_id().fill("yaohongyi@wezhuiyi.com")
        login_page.password().fill("admin@123")
        login_page.button("登录").click()
        login_page.button("call2").click()
        context.wait_for_event("page")  # 等待新标签页加载
        page.close()
        context.close()
        browser.close()
